//
//  SwjInfoTableViewCell.m
//  OutesIOS
//
//  Created by norman on 2018/12/2.
//  Copyright © 2018 norman. All rights reserved.
//

#import "SwjInfoTableViewCell.h"
#import "UITapLabel.h"

@interface SwjInfoTableViewCell()


@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *lbArea;
@property (nonatomic,strong) UILabel *lbCoeff;
@property (nonatomic,strong) UILabel *lbCold;
@property (nonatomic,strong) UILabel *lbHeat;
@property (nonatomic,strong) UILabel *lbTotalCold;
@property (nonatomic,strong) UILabel *lbTotalHeat;
@property (nonatomic,strong) UILabel *lbCorrectCold;
@property (nonatomic,strong) UILabel *lbCorrectHeat;
@property (nonatomic,strong) UIImageView *rightImage;

@end

@implementation SwjInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    self.contentView.width = kScreen_Width;
    //标题
    self.titleLabel = [UILabel labelSingleLineFontSize:kListTitleFontSize content:@"系统2222222"];
    self.titleLabel.x = CELL_PADDING_LEFT;
    self.titleLabel.y = CELL_PADDING_TOP;
    self.titleLabel.textColor = BSBlackTextColor;
    [self.contentView addSubview:self.titleLabel];
    
    UILabel *lb1 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"面积:"];
    lb1.textColor = CM_TABLE_DETAIL_COLOR;
    lb1.x = CELL_PADDING_LEFT;
    lb1.y = CGRectGetMaxY(self.titleLabel.frame) + CELL_PADDING_TOP;
    [self.contentView addSubview:lb1];
    self.lbArea = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbArea.x = CGRectGetMaxX(lb1.frame);
    self.lbArea.y = CGRectGetMaxY(lb1.frame) - self.lbArea.height;
    self.lbArea.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.lbArea];
    
    UITapLabel *lb4 = [[UITapLabel alloc]init];
    lb4.x = kScreen_Width/2;
    lb4.y = lb1.y;
    lb4.width = [Tools sizeOfSingleLineText:@"同时使用系数:" withSize:kListDetailFontSize].width;
    lb4.height = [Tools sizeOfSingleLineText:@"同时使用系数:" withSize:kListDetailFontSize].height;
    lb4.text = @"同时使用系数:";
    lb4.font = [UIFont systemFontOfSize:kListDetailFontSize];
    lb4.textColor = CM_BLUE_COLOR;
    [lb4 addTargetsBlock:^(id obj) {
        //修改使用系数
        if (self.coeffModifyClicked) {
            self.coeffModifyClicked();
        }
    }];
    [self.contentView addSubview:lb4];
    self.lbCoeff = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbCoeff.x = CGRectGetMaxX(lb4.frame);
    self.lbCoeff.y = CGRectGetMaxY(lb4.frame) - self.lbCoeff.height;
    self.lbCoeff.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.lbCoeff];
    
    
    UILabel *lb2 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统冷负荷:"];
    lb2.textColor = CM_TABLE_DETAIL_COLOR;
    lb2.x = CELL_PADDING_LEFT;
    lb2.y = CGRectGetMaxY(self.lbArea.frame) + CELL_PADDING_TOP;
    [self.contentView addSubview:lb2];
    self.lbTotalCold = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbTotalCold.x = CGRectGetMaxX(lb2.frame);
    self.lbTotalCold.y = lb2.y;
    self.lbTotalCold.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.lbTotalCold];
    
    UILabel *lb3 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统热负荷:"];
    lb3.textColor = CM_TABLE_DETAIL_COLOR;
    lb3.x = kScreen_Width/2;
    lb3.y = lb2.y;
    [self.contentView addSubview:lb3];
    self.lbTotalHeat = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbTotalHeat.x = CGRectGetMaxX(lb3.frame);
    self.lbTotalHeat.y = lb3.y;
    self.lbTotalHeat.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.lbTotalHeat];
    
    UILabel *lb5 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"机组制冷能力:"];
    lb5.textColor = CM_TABLE_DETAIL_COLOR;
    lb5.x = CELL_PADDING_LEFT;
    lb5.y = CGRectGetMaxY(self.lbTotalCold.frame) + CELL_PADDING_TOP;
    [self.contentView addSubview:lb5];
    self.lbCold = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbCold.x = CGRectGetMaxX(lb5.frame);
    self.lbCold.y = lb5.y;
    self.lbCold.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.lbCold];
    
    UILabel *lb6 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"机组制热能力:"];
    lb6.textColor = CM_TABLE_DETAIL_COLOR;
    lb6.x = kScreen_Width/2;
    lb6.y = lb5.y;
    [self.contentView addSubview:lb6];
    self.lbHeat = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbHeat.x = CGRectGetMaxX(lb6.frame);
    self.lbHeat.y = lb6.y;
    self.lbHeat.textColor = CM_TABLE_TITLE_COLOR;
    [self.contentView addSubview:self.lbHeat];
    
    UILabel *lb7 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"修正制冷量:"];
    lb7.textColor = CM_TABLE_DETAIL_COLOR;
    lb7.x = CELL_PADDING_LEFT;
    lb7.y = CGRectGetMaxY(self.lbCold.frame) + CELL_PADDING_TOP;
    lb7.hidden = YES;
    [self.contentView addSubview:lb7];
    self.lbCorrectCold = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbCorrectCold.x = CGRectGetMaxX(lb7.frame);
    self.lbCorrectCold.y = lb7.y;
    self.lbCorrectCold.textColor = CM_TABLE_TITLE_COLOR;
    self.lbCorrectCold.hidden = YES;
    [self.contentView addSubview:self.lbCorrectCold];
    
    UILabel *lb8 = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"修正制热量:"];
    lb8.textColor = CM_TABLE_DETAIL_COLOR;
    lb8.x = kScreen_Width/2;
    lb8.y = lb7.y;
    lb8.hidden = YES;
    [self.contentView addSubview:lb8];
    self.lbCorrectHeat = [UILabel labelSingleLineFontSize:kListDetailFontSize content:@"系统2222222"];
    self.lbCorrectHeat.x = CGRectGetMaxX(lb8.frame);
    self.lbCorrectHeat.y = lb7.y;
    self.lbCorrectHeat.textColor = CM_TABLE_TITLE_COLOR;
    self.lbCorrectHeat.hidden = YES;
    [self.contentView addSubview:self.lbCorrectHeat];
    
    self.contentView.height = CGRectGetMaxY(self.lbCold.frame) + CELL_PADDING_BOTTOM;
    
    //右边的导航图标
    self.rightImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"select_user_up"]];
    self.rightImage.x = kScreen_Width - CELL_PADDING_LEFT - self.rightImage.width;
    self.rightImage.centerY = self.contentView.height/2;
//    [self.contentView addSubview:self.rightImage];
}

- (void)setData:(MainEquipSystemData *)data {
    self.titleLabel.text = data.system_name;
    self.lbArea.text = [NSString stringWithFormat:@"%.1f㎡", data.area];
    self.lbCoeff.text = [NSString stringWithFormat:@"%.2f", data.coeff];
    self.lbTotalCold.text = [NSString stringWithFormat:@"%.1fKw", [self calc:data.total_cold_load withCoeff:data.coeff]];
    self.lbTotalHeat.text = [NSString stringWithFormat:@"%.1fKw", data.total_heat_load];
    self.lbCold.text = [NSString stringWithFormat:@"%.1fKw", data.correct_cold_load];
    self.lbHeat.text = [NSString stringWithFormat:@"%.1fKw", data.correct_heat_load];
    self.lbCorrectCold.text = [NSString stringWithFormat:@"%.1fKw", data.correct_cold_load];
    self.lbCorrectHeat.text = [NSString stringWithFormat:@"%.1fKw", data.correct_heat_load];
}

- (double)calc:(double)coldLoad withCoeff:(double)coeff {
    double add_coeff = 1.5 - 0.5*coeff;
    return coldLoad*0.7*add_coeff*coeff;
}

- (void)setSubContentClosed:(BOOL)isClosed {
    if (isClosed) {
        UIImage *image = [UIImage imageNamed:@"select_user_down"];
        self.rightImage.image = image;
    }
    else {
        UIImage *image = [UIImage imageNamed:@"select_user_up"];
        self.rightImage.image = image;
    }
}

- (CGFloat)getHeight {
    return self.contentView.height;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
